<?php  
class ControllerCommonHome extends Controller {
	public function index() {
		$this->document->setTitle('首页');
		$this->document->setKeywords($this->config->get('config_meta_keywords'));
		$this->document->setDescription($this->config->get('config_meta_description'));
		$this->data['heading_title'] = $this->config->get('config_title');
        $this->load->model('article/category');
        $this->load->model('article/article');
        
        /* 导航 */
        $this->data['breadcrumbs'] = array();
		$this->data['breadcrumbs'][] = array(
			'text'      => '首页',
			'href'      => $this->url->link('common/home'),			
			'separator' => false
		);
        
        /* Banner */
        $this->load->model('tool/image');
		$this->document->addScript('home/view/javascript/jquery/nivo-slider/jquery.nivo.slider.pack.js');
		$this->document->addStyle('home/view/stylesheet/slideshow.css');
        
		$this->load->model('design/banner');
		$this->load->model('tool/image');

		$this->document->addScript('home/view/javascript/jquery/jquery.cycle.js');
        $this->data['width'] = '980';
		$this->data['height'] = '280';
		$this->data['banners'] = array();
        
        $results = array();
        $banners = $this->model_design_banner->getBanners();
        foreach($banners as $banner)
        {
            $results = $this->model_design_banner->getBanner($banner['banner_id']);
            foreach ($results as $result) {
                if (file_exists(DIR_IMAGE . $result['image'])) {
                    $this->data['banners'][] = array(
                        'title' => $result['title'],
                        'link'  => $result['link'],
                        'image' => $this->model_tool_image->resize($result['image'], $this->data['width'], $this->data['height'])
                    );
                }
            }
        }
        
        /* 联系方式 */
        $this->data['contact_email'] = $this->config->get('config_email');
        $this->data['contact_telephone'] = $this->config->get('config_telephone');
        $this->data['contact_address'] = $this->config->get('config_address');
        $this->data['contact_owner'] = $this->config->get('config_owner');
        $this->data['contact_fax'] = $this->config->get('config_fax');
        
        /* 热门推荐 */
        $hot_article = $this->model_article_article->getTopArticle(5);
        foreach($hot_article as $hot)
        {
            $path = $this->model_article_category->getPath($hot['category_id']);
            $this->data['hot_article'][] = array(
                'name' => $hot['title'],
                'href' => $this->url->link('article/article', '&path='.$path.'&article_id='.$hot['article_id'], 'SSL')
            );
        }
        
        
        
        $this->template = 'common/home.tpl';
		$this->children = array(
			'common/footer',
			'common/header'
		);
		$this->response->setOutput($this->render());
	}
}
?>